package com.atguigu.gmall.product.service.impl;

import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.mapper.BaseTradeMarkMapper;
import com.atguigu.gmall.product.service.BaseTradeMarkService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BaseTradeMarkServiceImpl extends ServiceImpl<BaseTradeMarkMapper,BaseTrademark> implements BaseTradeMarkService {

    @Autowired
    private BaseTradeMarkMapper baseTradeMarkMapper;

    //添加品牌
    @Override
    public Boolean saveTradeMark(BaseTrademark baseTrademark) {
        int insert = baseTradeMarkMapper.insert(baseTrademark);
        return insert > 0;
    }


    //删除品牌
    @Override
    public boolean deleteTradeMark(Long id) {
        QueryWrapper<BaseTrademark> baseTrademarkQueryWrapper = new QueryWrapper<>();
        baseTrademarkQueryWrapper.eq("id", id);
        int delete = baseTradeMarkMapper.delete(baseTrademarkQueryWrapper);
        return delete > 0;
    }

    //获取品牌分页列表
    @Override
    public IPage getBaseTradeMarekList(Page<BaseTrademark> objectpage) {
        //构建查询条件
        QueryWrapper<BaseTrademark> baseTrademarkQueryWrapper = new QueryWrapper<>();
        baseTrademarkQueryWrapper.orderByDesc("id");
        IPage<BaseTrademark> baseTrademarkIPage = baseTradeMarkMapper.selectPage(objectpage, baseTrademarkQueryWrapper);
        return baseTrademarkIPage;
    }


}
